package com.yiming.rabbitmq.config;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 曾衣铭
 * @Date: 2020/09/27/10:23
 * @Description:创建交换机 队列 和绑定关系
 */
@Configuration
public class RabbitmqConfig {
    @Bean
    public FanoutExchange exchange(){
        //创建fanout类型交换机
        return new FanoutExchange("fanout_exchange");
    }

    @Bean
    public Queue queue(){
        //创建队列
        return new Queue("fanout_queue");
    }

    @Bean
    public Binding binding(){
        //绑定交换机和队列
        return BindingBuilder.bind(queue()).to(exchange());
    }
}
